#!/usr/bin/env node

import { isPathInIgnoredDirectory } from './dist/utils/path-utils.js';
import { simpleCodeParser } from './dist/processors/simple-parser.js';
import { MAX_FILE_SIZE_BYTES } from './dist/constants/index.js';
import fs from 'fs';

// Test a few files to see why they're being skipped
const testFiles = [
    './src/index.ts',
    './package.json', 
    './tsconfig.json',
    './README.md',
    './cli.js'
];

console.log('MAX_FILE_SIZE_BYTES:', MAX_FILE_SIZE_BYTES);

for (const filePath of testFiles) {
    try {
        console.log(`\n=== Testing ${filePath} ===`);
        
        // Check if file exists
        if (!fs.existsSync(filePath)) {
            console.log('❌ File does not exist');
            continue;
        }
        
        // Check if in ignored directory
        const isIgnored = isPathInIgnoredDirectory(filePath);
        console.log(`Ignored directory check: ${isIgnored}`);
        
        // Check file size
        const stats = fs.statSync(filePath);
        console.log(`File size: ${stats.size} bytes (max: ${MAX_FILE_SIZE_BYTES})`);
        const sizeLimitExceeded = stats.size > MAX_FILE_SIZE_BYTES;
        console.log(`Size limit exceeded: ${sizeLimitExceeded}`);
        
        // Parse the file
        const blocks = await simpleCodeParser.parseFile(filePath);
        console.log(`Blocks found: ${blocks.length}`);
        
        // Summary
        const shouldBeSkipped = isIgnored || sizeLimitExceeded || blocks.length === 0;
        console.log(`Should be skipped: ${shouldBeSkipped}`);
        
    } catch (error) {
        console.error(`❌ Error processing ${filePath}:`, error.message);
    }
}